//
// Created by Max on 2025/5/28.
//

#ifndef ALL_MIC_DETECT_MIC_CONFIG_H
#define ALL_MIC_DETECT_MIC_CONFIG_H
#include "mi_voc.h"
#include "mi_common.h"

typedef MI_RESULT (*pFUNC_VOC_INIT)(MI_VOC_InitParams_t *pstInitParams);
typedef MI_RESULT (*pFUNC_VOC_DEINIT)();
typedef MI_RESULT (*pFUNC_VOC_OPEN)(const MI_VOC_OpenParams_t *pstOpenParams, MI_HANDLE *phVoc);
typedef MI_RESULT (*pFUNC_VOC_CLOSE)(MI_HANDLE hVoc);
typedef MI_RESULT (*pFUNC_VOC_READ)(MI_HANDLE hVoc, MI_VOC_ReadParams_t *pstReadParams, MI_VOC_ReadOutputParams_t *pstReadOutputParams);
typedef MI_RESULT (*pFUNC_VOC_GET_ATTR)(MI_HANDLE hVoc, MI_VOC_AttrType_e eAttrType, const void *pInputParams, void *pOutputParams);
typedef MI_RESULT (*pFUNC_VOC_SET_ATTR)(MI_HANDLE hVoc, MI_VOC_AttrType_e eAttrType, const void *pAttrParams);
typedef MI_RESULT (*pFUNC_VOC_GET_HANDLE)(const MI_VOC_QueryHandleParams_t *pstQueryParams, MI_HANDLE *phVoc);

class MicConfig {

public:
    MicConfig();
    ~MicConfig();
    int Init(int channelNum, int sampleRate);
    int DeInit();
    int readMic(void *data, unsigned int frame_count);
    int getMicPeriodSize();
    int getMicPeriodCount();

private:
    int InitFunc();
    int InitMic();
    int DeInitMic();
    int OpenMic(int channelNum, int sampleRate);
    int CloseMic();

    int getHandle(MI_HANDLE *phVoc);

private:
    pFUNC_VOC_INIT g_pFunc_voc_init;
    pFUNC_VOC_DEINIT g_pFunc_voc_deinit;
    pFUNC_VOC_OPEN g_pFunc_voc_open;
    pFUNC_VOC_CLOSE g_pFunc_voc_close;
    pFUNC_VOC_READ g_pFunc_voc_read;
    pFUNC_VOC_GET_ATTR g_pFunc_voc_get_attr;
    pFUNC_VOC_SET_ATTR g_pFunc_voc_set_attr;
    pFUNC_VOC_GET_HANDLE g_pFunc_voc_get_handle;

    MI_HANDLE mHandle;
    void *pLibraryHandle;

};


#endif //ALL_MIC_DETECT_MIC_CONFIG_H
